package com.ningxia.water.controller;


import com.ningxia.water.reuslt.Result;
import com.ningxia.water.reuslt.ResultResponse;
import com.ningxia.water.service.ITsApplicantPlanService;
import com.ningxia.water.service.ITsWellInfoService;
import com.ningxia.water.utils.LogUtils;
import com.ningxia.water.vo.out.ApplicantAndWellsVo;
import com.ningxia.water.vo.out.ChartVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author huangzhen
 * @create 2021-03-17 9:27
 * 一张图
 */
@RestController
@RequestMapping("/chart")
@Api(tags = {"业务管理-地图界面API"})
public class ChartController {

    @Autowired
    private ITsWellInfoService wellInfoService;

    @Autowired
    private ITsApplicantPlanService applicantPlanService;


    /**
     * 统计所有用户的各种水量信息-年份指标
     *
     * @param year
     * @return
     */
    @GetMapping("/info")
    @ApiOperation(value = "统计所有用户的各种水量信息-年份指标")
    public Result allChartInfo(@RequestParam("year") String year) {
        //机井总数
        int wellCount = wellInfoService.count();
        //year来查询计划水量、购买水量
        ChartVo chartVo = applicantPlanService.getAllVolume(year);
//        LogUtils.getLogInstance().info(chartVo.toString());
        chartVo.setCount(wellCount);
        return ResultResponse.getSuccessResult(chartVo);
    }


    /**
     * 关于报警
     * 1.如果累计水量达到当年计划水量的90%后，将此用户的全部机井状态设置为4444
     * 2.如果机井中设备出现故障，将机井设置为4444状态
     * 也就是说：我只需要判断机井状态是4444的用户
     *
     * @return
     */
    @GetMapping("/exceptionApplicant")
    @ApiOperation(value = "当前报警用户及其对应机井")
    public Result exceptionApplicant() {
        List<ApplicantAndWellsVo> list = applicantPlanService.findAllWarnWells();
        return ResultResponse.getSuccessResult(list);
    }


}
